jQuery.extend({
    getByName: function (name) {  //根据名称获取对象
        var exp = '';
        var names = name.split(',');
        for (var i = 0; i < names.length; i++) {
            exp += ',[name=\'' + names[i] + '\']';
        }
        exp = exp.substr(1);
        return $(exp);
    },
    setRidioValueByName: function (name, value) {  //根据名称设置riadio值
        var names = name.split(',');
        for (var i = 0; i < names.length; i++) {
            var exp = '[name=\'' + names[i] + '\']';
            $(exp).each(function () {
                if (this.value == value) {
                    this.checked = true;
                    return;
                }
            });
        }
    },

    //动态添加样式表 AddCss('a{background-color:red;color:black;padding:20px;}')
    addCss: function (c) {
        var Sty = document.createElement('style');
        Sty.type = 'text/css';
        if ($.browser.msie) {
            Sty.styleSheet.cssText = c;
        }
        else {
            var Frag = document.createDocumentFragment();
            Frag.appendChild(document.createTextNode(c));
            Sty.appendChild(Frag);
        }
        document.getElementsByTagName('head')[0].appendChild(Sty);
    }
});

jQuery.fn.extend({
    getValues: function () {
        var ret = {};
        this.each(function () {
            $(this).find('[name]').each(function () {
                if ((this.type == 'radio' || this.type == 'checkbox')) {
                    if (this.checked == true) {
                        ret[this.name] = $(this).val();
                    }
                }
                else {
                    ret[this.name] = $(this).val();
                }
            });
        });
        return ret;
    },
    setValues: function (values) {
        this.each(function () {
            $(this).find('[name]').each(function () {
                var value = values[this.name];
                if (value != undefined) $(this).val(value);
            });
        });
        return this;
    },
    AjaxPost: function (url, callback, params) {
        var values = this.getValues();
        if (params) {
            for (var i in params) {
                values[i] = params[i];
            }
        }
        $.ajax(url,
         {
             complete: callback,
             data: values,
             type: 'POST'
         }
        );
    },
    Blink: function (delay) { //闪烁指定对象
        this.each(function () {
            var obj = this;
            if (obj.IntervalID == undefined) {
                var isshow = true;
                if (delay == undefined) delay = 500;
                obj.IntervalID = setInterval(function () {
                    isshow = !isshow;
                    if (isshow) {
                        $(obj).show();
                    }
                    else {
                        $(obj).hide();
                    }
                }, delay);
            }
        });
    },
    StopBlink: function () {
        this.each(function () {
            var obj = this;
            if (obj.IntervalID) {
                clearInterval(obj.IntervalID);
                obj.IntervalID = undefined;
            }
        });
    }
});